/**
 * Title : jFamilyTree
 * Description: jFamilyTree
 * About: Designed and rewritten by Andreas Lundgren, based on the Treebolic application suite
 * Copyright:	(c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.model.graph;

/**
 * Graph edge
 * 
 * @author Bernard Bou
 */
public class GraphEdge
{
	// U S E R D A T A

	/**
	 * User data
	 */
	private Object theUserData;

	/**
	 * Whether this edge is tree edge (null=undetermined)
	 */
	private Boolean isTreeEdge;

	// D A T A

	/**
	 * Source node
	 */
	private GraphNode theFromNode;

	/**
	 * Destination node
	 */
	private GraphNode theToNode;

	// C O N S T R U C T O R

	/**
	 * Constructor
	 * 
	 * @param thisFromNode
	 *        source node
	 * @param thisToNode
	 *        destination node
	 */
	public GraphEdge(GraphNode thisFromNode, GraphNode thisToNode, Boolean isTreeEdgeFlag)
	{
		theFromNode = thisFromNode;
		theToNode = thisToNode;
		isTreeEdge = isTreeEdgeFlag;
	}

	/**
	 * Make inverse edge
	 * 
	 * @param thisEdge
	 *        edge
	 * @return edge
	 */
	static GraphEdge makeReverseOf(GraphEdge thisEdge)
	{
		return new GraphEdge(thisEdge.getTo(), thisEdge.getFrom(), thisEdge.getIsTreeEdge());
	}

	/**
	 * Get source node
	 * 
	 * @return source node
	 */
	public GraphNode getFrom()
	{
		return theFromNode;
	}

	/**
	 * Get destination node
	 * 
	 * @return destination node
	 */
	public GraphNode getTo()
	{
		return theToNode;
	}

	/**
	 * Whether this edge is tree edge (null=undetermined)
	 */
	public Boolean getIsTreeEdge()
	{
		return isTreeEdge;
	}

	/**
	 * Get user data
	 * 
	 * @return user data
	 */
	public Object getUserData()
	{
		return theUserData;
	}

	/**
	 * Set user data
	 * 
	 * @param thisUserData
	 *        user data
	 */
	public void setUserData(Object thisUserData)
	{
		theUserData = thisUserData;
	}

	/**
	 * Whether this edge is tree edge (null=undetermined)
	 * 
	 * @return Boolean (null=undetermined)
	 */
	public Boolean get()
	{
		return isTreeEdge;
	}

	/**
	 * Get node other than
	 * 
	 * @param thisNode
	 *        reference node
	 * @return node
	 */
	public GraphNode getOtherNode(GraphNode thisNode)
	{
		return thisNode.equals(theFromNode) ? theToNode : theFromNode;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		return theFromNode.toString() + " -> " + theToNode.toString();
	}
}
